package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"net/http"
	"sync"
	"time"
)

func main() {
	start := time.Now()
	var wg sync.WaitGroup
	for i := 0; i < 10; i++ {
		wg.Add(1)
		go func() {
			doRequest()
			wg.Done()
		}()
		fmt.Println(i)
	}
	wg.Wait()
	end := time.Since(start)
	fmt.Println("time is :", end.Seconds())
}

func doRequest() {
	url := "http://127.0.0.1:8100/api/unitable/v1/event"
	var body = `{"events":[{"eventName":"workSpaceCreateEvent","tag":"xxx","version_id":1,"module":"workspace","subModule":"workspace_create","params":"{\"origin_data\":{},\"new_data\":{\"id\":0,\"pid\":1,\"workspace_name\":\"xxx\",\"en_workspace_name\":\"xxx\",\"item_sort\":\"{}\",\"color\":\"#dfdrfdf\",\"created_by\":\"xxx\",\"icon\":\"family\",\"icon_color\":\"#dfdrfdf\"}}"}]}`
	var buf = bytes.NewBuffer([]byte(body))
	req, err := http.NewRequest(http.MethodPost, url, buf)
	if err != nil {
		panic(err)
	}
	req.Header.Add("Content-Type", "application/json")
	req.Header.Add("TenantID", "2")
	req.Header.Add("Authorization", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE2NjM2NjUxNDgsInV1aWQiOiJmNjdhMDJlOC01Nzk1LTQwMzQtOTY4Ni1jOGFiMzUxMDVlNjIifQ.3xShw6t5S7_VOYnRgxhe4Tswlw6S8iSnApqFWAntq_A")
	client := http.Client{}
	resp, err := client.Do(req)
	if err != nil {
		panic(err)
	}

	result, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(result))
}
